'use strict';

import React from 'react';

import {
  StyleSheet,
  View,
  Image,
  TouchableOpacity,
  Text
} from 'react-native';

import SizeUtils from '../../common/SizeUtils';
import ToastUtils from '../../common/ToastUtils';
import Config from '../../config';
import BaseComponent from '../common/BaseComponent';
import TImage from '../../components/TImage';
import CommonShowViewFullScreenAction from '../../actions/common/CommonShowViewFullScreenAction';
import JifenMallToSignAction from '../../actions/jifenmall/JifenMallToSignAction';

class QianDaoView extends BaseComponent {
  componentWillUpdate(nextProps, nextState) {
    if (nextState.mallqiandao) {
       nextState.mallqiandao=false;
       // ToastUtils.show(nextState.detail);
       this._onPressClose();
       this.props.fullScreenData.jfref&&this.props.fullScreenData.jfref();
       this.gotoPage(Config.pages.jifenmall_qiandao_page, {});
    }
  }
  _onPressClose() {
    new CommonShowViewFullScreenAction().call(this, null);
  }
  _renderCloseButton() {
    return (
      <TouchableOpacity style={{position:"absolute", top:SizeUtils.translateDesignHeightToCode(30),
          width:50,height:50,right:10, flexDirection:"row", justifyContent:"center"}}
          onPress={this._onPressClose.bind(this)}>
        <TImage source={require("../../../resource/images/jifenmall/home_icon_guanbi.png")} style={{
          width:50, height:50,
        }}/>
      </TouchableOpacity>
    )
  }
  render() {
    const item = this.props.fullScreenData;
    return (
      <View style={{position:"absolute", top:0,right:0,bottom:0,left:0,backgroundColor:'#0006'}}>
      	<View style={{
      		marginTop:SizeUtils.translateDesignHeightToCode(300),
      		marginLeft:SizeUtils.translateDesignWidthToCode(80),
      		marginRight:SizeUtils.translateDesignWidthToCode(80),
      		height:SizeUtils.translateDesignHeightToCode(610),
      		alignItems: 'center',
      		backgroundColor:'#fff0'
      	}}>
      		<Image source={require("../../../resource/images/jifenmall/home_tanchuang_qiandao.png")}
            	style={{padding:10,alignItems:'center'}}>
            	<Text style={{color:'#fff',fontSize:34,fontWeight:"bold",marginTop:40}}>每日签到</Text>
            	<View style={{marginTop:10,width:110,height:24,
            		alignItems: 'center',justifyContent: 'center',
            		borderRadius:12,backgroundColor:'#000'}}>
				  <Text style={{color:'#fff',fontSize:11,}}>{`已累计签到${item.continue_days}天`}</Text>
            	</View>
              {
                item.is_today_signed===0?
                <Text style={{color:'#999',fontSize:13,marginTop:45}}>签到得积分</Text>:
                <View style={{marginTop:45,height:10}}/>
              }
              {
                item.is_today_signed===0?
                <Text style={{color:'#000',fontSize:14,marginTop:10}}>{`本次签到可获得3积分`}</Text>:
                <View style={{marginTop:10,height:10}}/>
              }
            	<TouchableOpacity style={{marginTop:35,height:36,
            		width:SizeUtils.getWindowSize().width-SizeUtils.translateDesignWidthToCode(280),
            		alignItems: 'center',justifyContent: 'center',
            		borderWidth:SizeUtils.translateDesignNumToCode(3),
            		borderColor:"#000",
            		borderRadius:18,backgroundColor:'#0000'}}
            		onPress={()=>{
                  if (item.is_today_signed===1) {
                    this._onPressClose();
                    this.gotoPage(Config.pages.jifenmall_qiandao_page, {});
                  }else{
                    new JifenMallToSignAction().call(this, {});
                  }
            		}}>
				  <Text style={{color:'#000',fontSize:14,}}>{item.is_today_signed===0?'签到':'已签到'}</Text>
            	</TouchableOpacity>
            	{this._renderCloseButton()}
           	</Image>
      	</View>
      </View>
    );
  }
}

const styles = StyleSheet.create({

});


export default QianDaoView;